-- grytole@gmail.com 28-Jun-2012

print('Running performance test')

isok, errmsg = sdl.init( {w = 720, h = 480, bpp = 32}, 'Performance test' )
if isok == false then
  print( 'SDL init failed:', errmsg )
  os.exit()
end



isok, retval = sdl.text( 'Some short text string',
                         {font = './examples/performance/ubuntu.ttf', size = 52},
                         {r = 128, g = 128, b = 128} )
if isok == false then
  print( 'Text rendering failed:', retval )
  os.exit()
else
  text = retval
end

stime = os.time()
for _ = 1, 1000 do
  sdl.blit( text, {x = 0, y = 0, w = text.w, h = text.h}, nil, {x = math.random(0,200), y = math.random(0,400)} )
  sdl.flip()
end
print('  Text test - 1000 iterations:', os.time() - stime)
sdl.shot('text.bmp')



isok, retval = sdl.fill( {w = 50, h = 50}, {r = 64, g = 128, b = 255} )
if isok == false then
  print( 'Rect rendering failed:', retval )
  os.exit()
else
  rect = retval
end

stime = os.time()
for _ = 1, 1000 do
  sdl.blit( rect, {x = 0, y = 0, w = rect.w, h = rect.h}, nil, {x = math.random(0,669), y = math.random(0,429)} )
  sdl.flip()
end
print('  Rect test - 1000 iterations:', os.time() - stime)
sdl.shot('rect.bmp')



isok, retval = sdl.image( './examples/performance/img.bmp' )
if isok == false then
  print( 'Image load failed:', retval )
  os.exit()
else
  img = retval
end

stime = os.time()
for _ = 1, 1000 do
  sdl.blit( img, {x = 0, y = 0, w = img.w, h = img.h}, nil, {x = math.random(0,619), y = math.random(0,379)} )
  sdl.flip()
end
print('  Image test - 1000 iterations:', os.time() - stime)
sdl.shot('image.bmp')



sdl.quit()

print('Done')

-- eof
